﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace PFAGame
{
    abstract class ALoot : AObject
    {
        private float radius = 1f;
        private float lifeTime = 60f;
        public float LifeTime
        {
            get { return lifeTime; }
            set { lifeTime = value; }
        }

        static SoundEffect sound;
        SoundEffectInstance soundInstance;

        public override void init()
        {
            base.init();

            if (sound == null)
                sound = ScreenManager.Singleton.Game.Content.Load<SoundEffect>("Sound_effects/take_bonus");
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = 0.2f;
            soundInstance.IsLooped = false;
        }

        public override void update(GameTime gameTime)
        {
            // durée de vie du loot
            lifeTime -= (float)gameTime.ElapsedGameTime.Ticks / 10000000;
            if (lifeTime < 0)
                GameplayScreen.Singleton.DeleteLootList.Add(this);

            // test de collision avec les joueurs
            List<AObject> players =  SphereCast(position, radius, GameplayScreen.Singleton.Players);
            foreach (APlayer player in players)
                applyBuff(player);
        }

        protected virtual void applyBuff(APlayer player)
        {
            soundInstance.Play();
        }
    }
}
